<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .container {
            width: 100vw;
            height: 100vh;
            position: relative;
            overflow: hidden;
        }

        .item {
            width: 240px;
            height: 160px;
            position: absolute;
            top: 50%;
            left: 0;
            transform: translateY(-50%);
            border-radius: 10px;
            box-shadow: 0 30px 50px #505050;
            background-size: cover;
            background-position: center;
            transition: 1s;
        }

        .item:nth-child(1),
        .item:nth-child(2) {
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            transform: translateY(0);
            box-shadow: none;
            border-radius: 0;
        }

        .item:nth-child(3) {
            left: 70%;
        }

        .item:nth-child(4) {
            left: calc(70% + 250px);
        }

        .item:nth-child(5) {
            left: calc(70% + 500px);
        }

        .item:nth-child(n+6) {
            left: calc(70% + 750px);
            opacity: 0;
        }

        .buttons {
            width: 100%;
            position: absolute;
            bottom: 50px;
            margin-left: -50px;
            text-align: center;
            display: flex;
            justify-content: center;
        }

        .buttons div {
            width: 120px;
            height: 50px;
            line-height: 50px;
            text-align: center;
            border-radius: 5px;
            margin: 0 25px;
            transition: .5s;
            cursor: pointer;
            user-select: none;
            font-size: 20px;
            color: #fff;
            background-color: rgba(0, 0, 0, 0.4);
            box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.2);
        }
    </style>
</head>
<body>
<div class="container">
    <div id="slide">
        <div class="item" style="background-image:url('../ProductPhoto/img.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_1.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_2.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_3.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_4.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_5.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_6.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_7.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_8.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_9.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_10.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_11.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_12.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_13.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_14.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_15.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_16.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_17.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_18.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_19.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_20.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_21.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_22.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_23.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_24.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_25.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_26.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_27.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_28.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_29.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_30.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_31.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_32.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_33.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_34.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_35.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_36.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_37.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_38.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_39.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_40.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_41.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_42.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_43.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_44.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_45.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_46.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_47.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_48.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_49.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_50.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_51.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_52.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_53.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_54.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_55.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_56.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_57.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_58.png')"></div>
        <div class="item" style="background-image:url('../ProductPhoto/img_59.png')"></div>
    </div>
    <div class="buttons">
        <div class="left">< Prev</div>
        <div class="center">购物车</div>
        <div class="right">Next ></div>
    </div>
</div>
<script>
    const leftBtn = document.querySelector(".buttons .left")
    const rightBtn = document.querySelector(".buttons .right")
    const slide = document.querySelector("#slide")
    let openClick = true // 节流处理 (保证动画执行过程，按钮不被重复点击)

    // 切换到下一张图片的函数
    function moveToNextImage() {
        if (openClick) {
            openClick = false
            const items = document.querySelectorAll(".item")
            slide.appendChild(items[0])

            setTimeout(() => openClick = true, 1000)
        }
    }

    // 使用setInterval每秒调用moveToNextImage
    const intervalId = setInterval(moveToNextImage, 1000)

    // 当点击左右按钮时，清除定时器以停止自动切换
    leftBtn.addEventListener("click", () => {
        clearInterval(intervalId)
        moveToNextImage()
    })

    rightBtn.addEventListener("click", () => {
        clearInterval(intervalId)
        moveToNextImage()
    })
</script>
</body>
</html>